package com.chat.simplechat.controller;

import com.chat.simplechat.entity.GiftBean;
import com.chat.simplechat.entity.LoginUser;
import com.chat.simplechat.event.GiftEvent;
import com.chat.simplechat.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author wangyabin
 * @date 2022/10/26 17:31
 */
@Controller
@RequestMapping("/gift")
public class GiftController {
    
    @Autowired
    private UserInfoService userInfoService;
    
    @Resource
    private ApplicationContext applicationContext;
    
    @ResponseBody
    @GetMapping("/randomGift")
    public String randomGift(GiftBean giftBean){
        applicationContext.publishEvent(new GiftEvent(this,giftBean));
        return "成功";
    }

    @GetMapping("/page/{username}")
    public String page(@PathVariable("username") String username, Model model){
        LoginUser user = userInfoService.getLoginUser(username);
        model.addAttribute("user",user);
        return "websocket/SimpleChat";
    }
}
